package com.grm.common.utils;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;

/**
 * desc: ajax工具类
 *
 * @author gaorimao
 * @since 2021-3-14
 */
public class AjaxUtils {
	/**
	 * dsec: 用来判断请求属不属于Ajax请求
	 * 
	 * @param request 请求
	 * @return true/false
	 */
	public static boolean isAjax(HttpServletRequest request) {
		String accept = request.getHeader("Accept");
		String contentType = request.getHeader("Content-Type");
		// 检查是否为Ajax请求
		if ((StringUtils.isNotEmpty(accept) && accept.contains("application/json")) ||
			(StringUtils.isNotEmpty(contentType) && contentType.contains("application/json"))) {
			return true;
		}
		return false;
	}
}
